package com.ebao.action.admin;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.ebao.action.base.BaseAction;
import com.ebao.constants.WebConstants;
import com.ebao.po.admin.TAdmin;
import com.ebao.service.admin.IAdminService;

/**
 * @author snow
 * @Date 2012-8-14
 */
public class AdminAction extends BaseAction {

	private static final long serialVersionUID = 4071239657330022980L;

	@Resource
	private IAdminService adminService;
	
	private String loginName;
	private String password;
	
	private String info;
	
	@Action(value = "login", results = {@Result(name =  SUCCESS, location = "index.jsp"),
			@Result(name = ERROR, location = "/login.jsp")})
	public String login() {
		TAdmin admin = adminService.login(loginName, password);
		if(admin != null){// 登陆成功
			log.info("" + admin + "登陆成功!");
			this.session.put(WebConstants.LOGIN_ADMIN, admin);
			return SUCCESS;
		} else {
			log.warn(loginName + "登录失败, 输入密码为" + password);
			info = "用户名或密码不正确";
			return ERROR;
		}
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}
	
}
